package cn.itcast.wanxinp2p.account.controller;

import cn.itcast.wanxinp2p.account.AccountApi;
import cn.itcast.wanxinp2p.account.model.AccountDTO;
import cn.itcast.wanxinp2p.account.model.AccountLoginDTO;
import cn.itcast.wanxinp2p.account.model.AccountRegisterDTO;
import cn.itcast.wanxinp2p.account.service.AccountService;
import cn.itcast.wanxinp2p.common.domain.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api("统一账户管理")
@Slf4j
@RequestMapping("/account")
public class AccountController implements AccountApi {
   @Autowired
    AccountService accountService;
    @ApiOperation("获取手机验证码")
    @GetMapping("/sms/{mobile}")
    @Override
    public RestResponse getSMSCode(@ApiParam(name = "mobile", value = "mobile", required = true)@PathVariable  String mobile) {
         RestResponse res=accountService.getSMSCode(mobile);
        return  res;
    }
    @ApiOperation("检验手机号与验证码")
    @GetMapping(value = "/{mobile}/{key}/{code}")
    @Override
    public RestResponse<Integer> checkMobile(@ApiParam(name = "mobile", value = "mobile", required = true)@PathVariable String mobile,@ApiParam(name = "key", value = "key", required = true)@PathVariable String key, @ApiParam(name = "code", value = "code", required = true)@PathVariable String code) {
           return accountService.checkMobile(mobile,key,code);

    }
    @ApiOperation("用户注册")
    @PostMapping(value = "/l/accounts")
    @Override
    public RestResponse<AccountDTO> register(@RequestBody   AccountRegisterDTO accountRegisterDTO) {
        return RestResponse.success(accountService.register(accountRegisterDTO));
    }
    @ApiOperation("用户登录")
    @PostMapping(value = "/l/accounts/session")
    @Override
    public RestResponse<AccountDTO> login(@RequestBody  AccountLoginDTO accountLoginDTO) {
        return RestResponse.success(accountService.login(accountLoginDTO));
    }
}
